package com.jinghua.treatment.service.impl;

import com.jinghua.treatment.entity.Medical;
import com.jinghua.treatment.entity.PrescriptionDetail;
import com.jinghua.treatment.entity.UsualPrescriptionVO;
import com.jinghua.treatment.entity.vo.PrescriptionVO;
import com.jinghua.treatment.mapper.PrescriptionDetailMapper;
import com.jinghua.treatment.mapper.PrescriptionMapper;
import com.jinghua.treatment.service.PrescriptionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by LV
 */
@Service("PrescriptionService")
public class PrescriptionServiceImpl implements PrescriptionService{

    @Resource
    private PrescriptionMapper prescriptionMapper;
    @Resource
    private PrescriptionDetailMapper prescriptionDetailMapper;

    @Override
    public int countAllPrescriptions(String userId) {
        return 0;
    }

    @Override
    public int countStatePrescriptions(Map map) {
        return 0;
    }

    @Override
    @Transactional
    public void savePrescription(PrescriptionVO prescriptionVO) {

        prescriptionVO.setPrescriptionTime(new Date());
        prescriptionMapper.insertSelective(prescriptionVO);

        int medIds[] = prescriptionVO.getMedId();
        int medNums[] = prescriptionVO.getMedNum();
        double medPrices[] = prescriptionVO.getMedPrice();
        if(medIds!=null&&medIds.length>0){//Integer id, Integer medicalId, Integer count, Double price
            for(int i = 0;i<medIds.length;i++){
                PrescriptionDetail  prescriptionDetail  = new PrescriptionDetail(prescriptionVO.getId(),medIds[i],medNums[i],medPrices[i]);
                prescriptionDetailMapper.insertSelective(prescriptionDetail);
            }
        }
    }

    @Override
    public List<UsualPrescriptionVO> selectAllUsualPrescription(String userId) {
        return null;
    }

    @Override
    public int addUsualPrescription(UsualPrescriptionVO param) {
        return 0;
    }

    @Override
    public List<Medical> getMedicalByName(String name) {
        return null;
    }

    @Override
    public Double getPrescriptionPriceByMedical(Map param) {
        return null;
    }

  /*  @Override
    public int countStatePrescriptions(Map map) {
        return prescriptionMapper.countStatePrescriptions(map);
    }

    @Override
    public int countAllPrescriptions(String userId) {
        return prescriptionMapper.countAllPrescriptions(userId);
    }

    @Override
    public List<PrescriptionVO> selectAllPrescriptions(PrescriptionVO param) {
        List<PrescriptionVO> result = prescriptionMapper.selectAllPrescriptions(param);
        for (PrescriptionVO object : result) {
            object.setPrescriptionDetail(prescriptionMapper.getPrescriptionDetailsById(object.getId()));
        }
        return result;
    }

    @Override
    public List<PrescriptionDetailVO> getPrescriptionDetailById(String id) {
        return prescriptionMapper.getPrescriptionDetailById(id);
    }*/

  /*  @Override
    public List<UsualPrescriptionVO> selectAllUsualPrescription(String userId) {
        List<UsualPrescriptionVO> result = prescriptionMapper.selectAllUsualPrescription(userId);
        for (UsualPrescriptionVO object : result) {
            object.setPrescriptionDetail(prescriptionMapper.getPrescriptionDetailById(object.getId()));
        }
        return result;
    }*/

 /*   @Override
    public int addPrescription(PrescriptionVO param) {
        prescriptionMapper.addPrescription(param);
        for(PrescriptionDetailVO object:param.getPrescriptionDetail()){
            object.setId(param.getId());
            prescriptionMapper.addPrescriptionDetails(object);
        }
        return 1;
    }*/

   /* @Override
    public int addUsualPrescription(UsualPrescriptionVO param) {
        prescriptionMapper.addUsualPrescription(param);
        for(PrescriptionDetailVO object:param.getPrescriptionDetail()){
            object.setId(param.getId());
            prescriptionMapper.addPrescriptionDetail(object);
        }
        return 1;
    }*/

  /*  @Override
    public List<Medical> getMedicalByName(String name) {
        Medical param = new Medical();
        param.setMedicalName(name);
        return prescriptionMapper.getMedicalByName(param);
    }*/

  /*  @Override
    public Double getPrescriptionPriceByMedical(Map param) {
        Double result = prescriptionMapper.getPrescriptionPriceByMedical(param);
        return result;
    }*/
}
